package com.xutils.netty.push;

import android.util.Log;
import com.xutils.utils.LogUtils;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;

/**
 * Created by ketian on 2014/9/24.
 */
public class PushChannelHandle extends SimpleChannelInboundHandler {

    private PushCallBack mListener;

    public PushChannelHandle(PushCallBack listener) {
        mListener = listener;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        LogUtils.d("handle:"+msg);
    }

    @Override
    public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
        LogUtils.d("推送长连接创建成功");
        mListener.onConnected();
    }


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        LogUtils.d("推送长连接异常");
        mListener.onDisconnect();
    }

}
